/*
 *  Cero Project - Copyright   2006 The Cero Developement Team 
 *  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade) 
 * 
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the Free 
 *  Software Foundation; either version 2 of the License, or (at your option) 
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 */

package org.ceroproject;

import javax.swing.JFrame;

import org.ceroproject.games.Game;
import org.ceroproject.games.GameEvent;
import org.ceroproject.games.GameInitializer;
import org.ceroproject.games.GameListener;
import org.ceroproject.games.InitializationException;
import org.ceroproject.games.RoundEvent;
import org.ceroproject.games.RoundListener;
import org.ceroproject.games.Rule;
import org.ceroproject.games.ValidationException;
import org.ceroproject.plugin.PluginManager;


/*
 * FIXME : IMPORTANT !!
 * This file must be put into a different project to have it work !
 * This problem will remain as long as Plugins aren't implemented !
 * Add the needed dependencies, too !
 */

public class IARunner {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PluginManager manager = PluginManager.getInstance();
		Game game = (Game) manager.getNewGame("Cero official uno");
		for (Rule r : manager.getGameRules(game.getGameName()))
			game.getRules().add(r);

		// 1 joueur humain suffira
		/*
		 * Player p = (Player) pmanager.getNewPlayer(game.getGameName());
		 * game.getPlayers().add(p); player = p;
		 */

		// 3 AI de chaque
		game.getPlayers().add(
				manager.getNewAI(game.getGameName(), "Standard AI"));
		game.getPlayers().add(
				manager.getNewAI(game.getGameName(), "Standard AI"));
		game.getPlayers().add(
				manager.getNewAI(game.getGameName(), "Standard AI"));
		// game.getPlayers().add(manager.getNewAI(game.getGameName(), "Standard
		// AI"));
		game.getPlayers()
				.add(manager.getNewAI(game.getGameName(), "Random AI"));
		game.getPlayers().get(0).setPlayerName("Toi");
		game.getPlayers().get(1).setPlayerName("Tom");
		game.getPlayers().get(2).setPlayerName("Léa");
		// game.getPlayers().get(3).setPlayerName("Gru");
		game.getPlayers().get(3).setPlayerName("Boulay");

		for (GameInitializer init : manager.getGameInitializers(game
				.getGameName()))
			game.getGameInitializers().add(init);

		game.addGameListener(new listener());

		try {
			game.startGame();
		} catch (InitializationException e) {
			e.printStackTrace();
		} catch (ValidationException e) {
			e.printStackTrace();
		}
		new JFrame().setVisible(true);
	}

	private static class listener implements RoundListener, GameListener {
		public void roundStart(RoundEvent e) {
			System.out.println("\n\tBeginning of a new Round");
		}

		public void roundEnd(RoundEvent e) {
			System.out.println("\tEnd of the current Round");
		}

		public void gameStart(GameEvent e) {
			System.out.println("Game started");
		}

		public void gameEnd(GameEvent e) {
			System.out.println("Game ended");
		}
	}

}
